Working With Pictures and PICT Files
This section describes the functions that let your application compress and decompress single-frame images stored as pictures and PICT files. See
"Working With Images,"
which begins on
Working With Images
, for information on compressing and manipulating single-frame images stored as pixel map structures. See
"Working With Sequences,"
which begins on
Working With Sequences
, for information on compressing and decompressing sequences of images.
As with image compression, the Image Compression Manager provides two sets of functions for working with compressed pictures. If you do not need to control the compression parameters, use the
CompressPicture
or
CompressPictureFile
functions. If you need more control over the operation, use the
FCompressPicture
or
FCompressPictureFile
functions.
The Image Compression Manager automatically expands compressed pictures when you display them. Use the
DrawPictureFile
function to display the contents of a picture file. If you want to alter the spatial characteristics of the image, use the
DrawTrimmedPicture
or
DrawTrimmedPictureFile
functions.
You can work with an image's control information by calling the
GetPictureFileHeader
function.
CompressPicture
The
CompressPicture
function compresses a single-frame image stored as a picture structure and places the result in another picture. If a picture with multiple pixel maps and other graphical objects is passed, the pixel maps will be compressed individually and the other graphic objects will not be affected.
pascal OSErr CompressPicture (PicHandle srcPicture,
PicHandle dstPicture,
CodecQ quality, CodecType cType);
-
srcPicture
-
Contains a handle to the source image, stored as a picture.
-
dstPicture
-
Contains a handle to the destination for the compressed image. The compressor resizes this handle for the result data.
-
quality
-
Specifies the desired compressed image quality. See
"Compression Quality Constants,"
for valid values.
-
cType
-
Specifies a compressor type. You must set this parameter to a valid compressor type (see
Table 3
for a list of the available compressor types). If the value passed in is 0, or
'raw '
, and the source picture is compressed, the destination picture is created as an uncompressed picture and does not require QuickTime to be displayed.
DESCRIPTION
The
CompressPicture
function compresses only image data. Any other types of data in the picture, such as text, graphics primitives, and previously compressed images, are not modified in any way and are passed through to the destination picture.
This function does not use the graphics port.
If your picture does not fit in memory, use the
CompressPictureFile
function, which is described on
CompressPictureFile
.
This function supports parameters governing image quality and compressor type. The compressor infers the other compression parameters from the image data in the source picture.
SPECIAL CONSIDERATIONS
The
CompressPicture
function doesn't compress pictures that contain compressed data. Do not alter data in pictures that are already compressed. Instead use
FCompressPicture
, described in the next section.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
noCodecErr
|
-8961
|
The Image Compression Manager could not find the specified compressor
|
SEE ALSO
If you need more control over the compression operation than is provided by the
CompressPicture
function, use the
FCompressPicture
function.
FCompressPicture
The
FCompressPicture
function compresses a single-frame image stored as a picture structure and places the result in another picture. If a picture with multiple pixel maps and other graphical objects is passed, the pixel maps will be compressed individually and the other graphic objects will not be affected.
pascal OSErr FCompressPicture (PicHandle srcPicture,
PicHandle dstPicture,
short colorDepth,
CTabHandle ctable,
CodecQ quality,
short doDither,
short compressAgain,
ICMProgressProcRecordPtr progressProc,
CodecType cType,
CompressorComponent codec);
-
srcPicture
-
Contains a handle to the source image, stored as a picture.
-
dstPicture
-
Contains a handle to the destination for the compressed image. The compressor resizes this handle for the result data.
-
colorDepth
-
Specifies the depth at which the image is to be compressed. If you set this parameter to 0, the Image Compression Manager determines the appropriate value for the source image. Values of 1, 2, 4, 8, 16, 24, and 32 indicate the number of bits per pixel for color images. Values of 34, 36, and 40 indicate 2-bit, 4-bit, and 8-bit grayscale, respectively, for grayscale images. Your program can determine which depths are supported by a given compressor by examining the compressor information structure returned by the
GetCodecInfo
function (see
"Getting Information About Compressor Components,"
which begins on
Getting Information About Compressor Components
, for more information).
-
ctable
-
Contains a handle to a custom color lookup table. Your program may use this parameter to indicate a custom color lookup table to be used with this image. If the value of the
colorDepth
parameter is less than or equal to 8 and the custom color lookup table is different from that of the source pixel map (that is, the
ctSeed
field values differ in the two pixel maps), the compressor remaps the colors of the image to the custom colors. If you set the
colorDepth
parameter to 16, 24, or 32, the compressor stores the custom color table with the compressed image. The compressor may use the table to specify the best colors to use when displaying the image at lower bit depths. The compressor ignores the
ctable
parameter when
colorDepth
is set to 33, 34, 36, or 40. If you set this parameter to
nil
, the compressor uses the color lookup table from the source pixel map.
-
quality
-
Specifies the desired compressed image quality. See
"Compression Quality Constants,"
for available values.
-
doDither
-
Indicates whether to dither the image. Use this parameter to indicate whether you want the image to be dithered when it is displayed on a lower-resolution screen. The following constants are available:
-
defaultDither
-
Indicates that the dithering in the source file is to be respected.
-
forceDither
-
Indicates that the specified image should be dithered whether the source uses dithering or not.
-
suppressDither
-
Indicates that dithering should not be used in any case. The ability to suppress dithering can be useful if, for example, you have a 32-bit color JPEG image drawn into a 8-bit buffer with a custom color table from the image. In that case, dithering would not be necessary and probably not desirable, particularly if the buffer were to be compressed with the graphics compressor.
-
compressAgain
-
Indicates whether to recompress compressed image data in the picture. Use this parameter to control whether any compressed image data that is in the source picture should be decompressed and then recompressed using the current parameters. Set the value of this parameter to
true
to recompress such data. Set the value of the parameter to
false
to leave the data as it is. Note that recompressing the data may have undesirable side effects, including image quality degradation.
-
progressProc
-
Points to a progress function structure. During the compression operation, the compressor may occasionally call a function you provide in order to report its progress (see
"Progress Functions,"
for more information about progress functions). If you have not provided a progress function, set this parameter to
nil
. If you pass a value of -1, you obtain a standard progress function.
-
cType
-
Specifies a compressor type. You must set this parameter to a valid compressor type (see
Table 3
for a list of the available compressor types). If the value passed in is 0, or
'raw '
, the resulting picture is not compressed and does not require QuickTime to be displayed.
-
codec
-
Contains a compressor identifier. Specify a particular compressor by setting this parameter to its compressor identifier. Alternatively, you may use one of the special identifiers:
-
anyCodec
-
Choose the first compressor of the specified type
-
bestSpeedCodec
-
Choose the fastest compressor of the specified type
-
bestFidelityCodec
-
Choose the most accurate compressor of the specified type
-
bestCompressionCodec
-
Choose the compressor that produces the smallest resulting data
-
You can also specify a component instance. This may be useful if you have previously set some parameter on a specific instance of a
codec
field and want to make sure that the specified instance is used for that operation.
DESCRIPTION
The
FCompressPicture
function compresses only image data. Any other types of data in the picture, such as text, graphics primitives, and previously compressed images, are not modified in any way and are passed through to the destination picture.
This function supports parameters governing image quality, compressor type, image depth, custom color tables, and dithering.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
noCodecErr
|
-8961
|
The Image Compression Manager could not find the specified compressor
|
codecSpoolErr
|
-8966
|
Error loading or unloading data
|
codecAbortErr
|
-8967
|
Operation aborted by the progress function
|
SEE ALSO
If you do not need such a high degree of control over the compression operation, use the
CompressPicture
function, described on
CompressPicture
.
CompressPictureFile
The
CompressPictureFile
function compresses a single-frame image stored as a picture file (PICT file) and places the result in another picture file.
pascal OSErr CompressPictureFile (short srcRefNum,
short dstRefNum,
CodecQ quality,
CodecType cType);
-
srcRefNum
-
Contains a file reference number for the source PICT file.
-
dstRefNum
-
Contains a file reference number for the destination PICT file. Note that the compressor overwrites the contents of the file referred to by
dstRefNum
. You must open this file with write permission. The destination file can be the same as the source file specified by the
srcRefNum
parameter.
-
quality
-
Specifies the desired compressed image quality. See
"Compression Quality Constants"
for available values.
-
cType
-
Specifies a compressor type. You must set this parameter to a valid compressor type (see
Table 3
for a list of the available compressor types). If the value passed in is 0, or
'raw '
, and the source picture is compressed, the destination picture is created as an uncompressed picture and does not require QuickTime to be displayed.
DESCRIPTION
The
CompressPictureFile
function compresses only image data. Any other types of data in the file, such as text, graphics primitives, and previously compressed images, are not modified in any way and are passed through to the destination picture. This function does not use the graphics port.
This function supports parameters governing image quality and compressor type. The compressor infers the other compression parameters from the image data in the source picture file.
SPECIAL CONSIDERATIONS
The
CompressPictureFile
function doesn't compress pictures that contain compressed data. Do not alter data in pictures that are already compressed. Instead use
FCompressPictureFile
, described in the next section.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
noCodecErr
|
-8961
|
The Image Compression Manager could not find the specified compressor
|
File Manager errors
SEE ALSO
If you need more control over the compression operation, use the
FCompressPictureFile
function.
FCompressPictureFile
The
FCompressPictureFile
function compresses a single-frame image stored as a picture file (PICT file) and places the result in another picture file.
pascal OSErr FCompressPictureFile (short srcRefNum,
short dstRefNum, short colorDepth,
CTabHandle ctable, CodecQ quality,
short doDither,
short compressAgain,
ICMProgressProcRecordPtr progressProc,
CodecType cType,
CompressorComponent codec);
-
srcRefNum
-
Specifies a file reference number for the source PICT file.
-
dstRefNum
-
Specifies a file reference number for the destination PICT file. Note that the compressor overwrites the contents of the file referred to by
dstRefNum
. You must open this file with write permissions. The destination file may be the same as the source file specified by the
srcRefNum
parameter.
-
colorDepth
-
Specifies the depth at which the image is to be compressed. If you set this parameter to 0, the Image Compression Manager determines the appropriate value for the source image. Values of 1, 2, 4, 8, 16, 24, and 32 indicate the number of bits per pixel for color images. Values of 34, 36, and 40 indicate 2-bit, 4-bit, and 8-bit grayscale, respectively, for grayscale images. Your program can determine which depths are supported by a given compressor by examining the compressor capability structure returned by the
GetCodecInfo
function (see
"Getting Information About Compressor Components,"
which begins on
Getting Information About Compressor Components
, for more information).
-
ctable
-
Contains a handle to a custom color lookup table. Your program may use this parameter to indicate a custom color lookup table to be used with this image. If the value of the
colorDepth
parameter is less than or equal to 8 and the custom color lookup table is different from that of the source pixel map (that is, the
ctSeed
field values differ in the two pixel maps), the compressor remaps the colors of the image to the custom colors. If you set the
colorDepth
parameter to 16, 24, or 32, the compressor stores the custom color table with the compressed image. The compressor may use the table to specify the best colors to use when displaying the image at lower bit depths. The compressor ignores the
ctable
parameter when
colorDepth
is set to 33, 34, 36, or 40. If you set this parameter to
nil
, the compressor uses the color lookup table from the source pixel map.
-
quality
-
Specifies the desired compressed image quality. See
"Compression Quality Constants"
for available values.
-
doDither
-
Indicates whether to dither the image. Use this parameter to indicate whether you want the image to be dithered when it is displayed on a lower-resolution screen. The following constants are available:
-
defaultDither
-
Indicates that the dithering in the source file is to be respected.
-
forceDither
-
Indicates that the specified image should be dithered whether the source uses dithering or not.
-
suppressDither
-
Indicates that dithering should not be used in any case. The ability to suppress dithering can be useful if, for example, you have a 32-bit, color JPEG image drawn into an 8-bit buffer with a custom color table from the image. In that case, dithering would not be necessary and probably not desirable, particularly if the buffer were to be compressed with the graphics compressor.
-
compressAgain
-
Indicates whether to recompress compressed image data in the picture. Use this parameter to control whether any compressed image data that is in the source picture should be decompressed and then recompressed using the current parameters. Set the value of this parameter to
true
to recompress such data. Set the value of this parameter to
false
to leave the data as it is. Note that recompressing the data may have undesirable side effects, including image quality degradation.
-
progressProc
-
Points to a progress function structure. During the compression operation, the compressor may occasionally call a function you provide in order to report its progress (see
"Progress Functions"
for more information about progress functions). If you have not provided a progress function, set this parameter to
nil
. If you pass a value of -1, you obtain a standard progress function.
-
cType
-
Specifies a compressor type. You must set this parameter to a valid compressor type (see
Table 3
for a list of the available compressor types). If the value passed in is 0, or
'raw '
and the source picture is compressed, the destination picture is created as an uncompressed picture and does not require QuickTime to be displayed.
-
codec
-
Contains a compressor identifier. Specify a particular compressor by setting this parameter to its compressor identifier. Alternatively, you may use one of the special identifiers:
-
anyCodec
-
Choose the first compressor of the specified type
-
bestSpeedCodec
-
Choose the fastest compressor of the specified type
-
bestFidelityCodec
-
Choose the most accurate compressor of the specified type
-
bestCompressionCodec
-
Choose the compressor that produces the smallest resulting data
-
You can also specify a component instance. This may be useful if you have previously set some parameter on a specific instance of a
codec
field and want to make sure that the specified instance is used for that operation.
DESCRIPTION
The
FCompressPicture
function compresses only image data. Any other types of data in the file, such as text, graphics primitives, and previously compressed images, are not modified in any way and are passed through to the destination picture file.
This function supports parameters governing image quality, compressor type, image depth, custom color tables, and dithering.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
noCodecErr
|
-8961
|
The Image Compression Manager could not find the specified compressor
|
codecAbortErr
|
-8967
|
Operation aborted by the progress function
|
File Manager errors
SEE ALSO
If you do not need such a high degree of control over the compression operation, use the
CompressPictureFile
function, described on
CompressPictureFile
.
DrawPictureFile
The
DrawPictureFile
function draws an image from a specified picture file (PICT file) in the current graphics port. Your program also specifies the destination rectangle for the image.
pascal OSErr DrawPictureFile (short refNum, const Rect *frame,
ICMProgressProcRecordPtr progressProc);
-
refNum
-
Contains a file reference number for the source PICT file.
-
frame
-
Contains a pointer to the rectangle into which the image is to be loaded. The compressor scales the source image to fit into this destination rectangle.
-
progressProc
-
Points to a progress function structure. During the operation, the draw function may occasionally call a function you provide in order to report its progress (see
"Progress Functions,"
for more information about progress functions). If you have not provided a progress function, set this parameter to
nil
. If you pass a value of -1, you obtain a standard progress function.
DESCRIPTION
The
DrawPictureFile
function is essentially the same as QuickDraw's
DrawPicture
routine, except that
DrawPictureFile
reads the picture from disk. (For details on
DrawPicture
, see
Inside Macintosh: Imaging
.) The Image Compression Manager performs any spooling that may be necessary when reading the picture file.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
codecAbortErr
|
-8967
|
Operation aborted by the progress function
|
File Manager errors
DrawTrimmedPicture
The
DrawTrimmedPicture
function draws an image that is stored as a picture into the current graphics port and trims that image to fit a region you specify.
pascal OSErr DrawTrimmedPicture (PicHandle srcPicture,
const Rect *frame, RgnHandle trimMask,
short doDither,
ICMProgressProcRecordPtr progressProc);
-
srcPicture
-
Contains a handle to the source image; stored as a picture.
-
frame
-
Contains a pointer to the rectangle into which the decompressed image is to be loaded.
-
trimMask
-
Contains a handle to a clipping region in the destination coordinate system. The decompressor applies this mask to the destination image and ignores any image data that fall outside the specified region. Set this parameter to
nil
if you do not want to clip the source image. In this case, this function acts like QuickDraw's
DrawPicture
routine, but it also allows you to control dithering and assign a progress function. (See
Inside Macintosh: Imaging
for more on
DrawPicture
.)
-
doDither
-
Indicates whether to dither the image. Use this parameter to indicate whether you want the image to be dithered when it is displayed on a lower-resolution screen. The following constants are available:
-
defaultDither
-
Indicates that the dithering in the source file is to be respected.
-
forceDither
-
Indicates that the specified image should be dithered whether the source uses dithering or not.
-
suppressDither
-
Indicates that dithering should not be used in any case. The ability to suppress dithering can be useful if, for example, you have a 32-bit, color JPEG image drawn into an 8-bit buffer with a custom color table from the image. In that case, dithering would not be necessary and probably not desirable, particularly if the buffer were to be compressed with the graphics compressor.
-
progressProc
-
Points to a progress function structure. During the compression operation, the compressor may occasionally call a function you provide in order to report its progress (see
"Progress Functions,"
for more information about progress functions). If you have not provided a progress function, set this parameter to
nil
. If you pass a value of -1, you obtain a standard progress function.
DESCRIPTION
The
DrawTrimmedPicture
function works with compressed image data--the source data stays compressed. The function trims the image to fit the specified clipping region.
Figure 10
shows how the
DrawTrimmedPicture
function works. It illustrates how you can use this function to save part of a picture (the clipped or uncompressed image data that is not within the trim region is ignored and is not included in the destination picture). All the remaining objects in the resulting image are clipped. You use QuickDraw's
OpenPicture
and
ClosePicture
routines to open and close the destination picture. (For more on
OpenPicture
and
ClosePicture
, see
Inside Macintosh: Imaging
.)
Note that if you just use a clip while making a picture, the data--though not visible--is still stored in the picture.
Figure 10
The operation of the
DrawTrimmedPicture
function
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
codecAbortErr
|
-8967
|
Operation aborted by the progress function
|
SEE ALSO
If your source image does not fit in memory, use the
DrawTrimmedPictureFile
function, which is described in the next section.
DrawTrimmedPictureFile
The
DrawTrimmedPictureFile
function draws an image that is stored as a picture file (PICT file) into the current graphics port and trims that image to fit a region you specify.
pascal OSErr DrawTrimmedPictureFile (short srcRefnum,
const Rect *frame,
RgnHandle trimMask,
short doDither,
ICMProgressProcRecordPtr progressProc);
-
srcRefNum
-
Contains a file reference number for the source PICT file.
-
frame
-
Contains a pointer to the rectangle into which the decompressed image is to be loaded.
-
trimMask
-
Contains a handle to a clipping region in the destination coordinate system. The decompressor applies this mask to the destination image and ignores any image data that fall outside the specified region. Set this parameter to
nil
if you do not want to clip the source image. In this case, this function acts like the
DrawPictureFile
function, which is described on
DrawPictureFile
.
-
doDither
-
Indicates whether to dither the image. Use this parameter to indicate whether you want the image to be dithered when it is displayed on a lower-resolution screen. The following constants are available:
-
defaultDither
-
Indicates that the dithering in the source picture file is to be respected.
-
forceDither
-
Indicates that the specified image should be dithered whether the source uses dithering or not.
-
suppressDither
-
Indicates that dithering should not be used in any case. The ability to suppress dithering can be useful if, for example, you have a 32-bit color JPEG image drawn into an 8-bit buffer with a custom color table from the image. In that case, dithering would not be necessary and probably not desirable, particularly if the buffer were to be compressed with the graphics compressor.
-
progressProc
-
Points to a progress function structure. During the compression operation, the compressor may occasionally call a function you provide in order to report its progress (see
"Progress Functions,"
for more information about progress functions). If you have not provided a progress function, set this parameter to
nil
. If you pass a value of -1, you obtain a standard progress function.
DESCRIPTION
The
DrawTrimmedPictureFile
function works with compressed image data--the source data stays compressed. The function trims the image to fit the specified clipping region. The Image Compression Manager handles any spooling issues that may arise when reading the picture file.
You can use this function to save part of a picture, since the image data that is not within the trim region is ignored and is not included in the destination picture file. All the reamining objects in the resulting object are clipped.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
memFullErr
|
-108
|
Not enough memory available
|
codecAbortErr
|
-8967
|
Operation aborted by the progress function
|
File Manager errors
GetPictureFileHeader
The
GetPictureFileHeader
function extracts the picture frame (the
picFrame
rectangle in the picture structure) and file header from a specified picture file (PICT file). Your program can use this information to determine how to draw an image without having to read the picture file.
pascal OSErr GetPictureFileHeader (short refNum, Rect *frame,
OpenCPicParams *header);
-
refNum
-
Contains a file reference number for the source PICT file.
-
frame
-
Contains a pointer to a rectangle that is to receive the picture frame rectangle of the picture file. This function places the
picFrame
rectangle from the picture structure into the rectangle referred to by the
frame
parameter. If you are not interested in this information, pass
nil
in this parameter.
-
header
-
Contains a pointer to an
OpenCPicture
parameters structure. The
GetPictureFileHeader
function places the header from the specified picture file into the structure referred to by the
header
parameter. Note that this function always returns a version 2 header. If the source file is a version 1 PICT file, the
GetPictureFileHeader
function converts the header into version 2 format before returning it to your application. See Inside Macintos
h: Imaging
for more information about picture headers and the
OpenCPicture
function. If you are not interested in this information, pass
nil
in this parameter.
DESCRIPTION
The
GetPictureFileHeader
function always returns a version 2 PICT file header. If the specified picture file is a version 1 file, the
GetPictureFileHeader
function synthesizes a version 2 header from the information available in the file header.
RESULT CODES
noErr
|
0
|
No error
|
paramErr
|
-50
|
Invalid parameter specified
|
File Manager errors
© 1999 Apple Computer, Inc.Previous | Overview | Contents | Next